import React, { useState } from 'react';
import './login.less'
import { Input,Grid, Modal  } from 'antd-mobile'
import request  from './../utils/request'
export default () => {
    const [code,setcode] = useState('');
    const [pwd,setpwd] = useState('');
    const login = ()=>{
        if(code==''){
            Modal.alert({
                content: '请输入账号',
                onConfirm: () => {
                  console.log('Confirmed')
                },
              })
            return;
        }
        if(pwd==''){
            Modal.alert({
                content: '请输入密码',
                onConfirm: () => {
                  console.log('Confirmed')
                },
              })
            return;
        }
        request('/web/login/bycode', {
            code: code,
            pwd: pwd,
            type: "account"
        }).then(res => {
            if(res.code == 0){
                window.location.href = window.location.origin+window.location.pathname+'#/lottery';
            }   
        })
    }
    return <div className='loginPage'>
        <div className='loginDesc'>输入账号登录</div>
        <div className='loginForm'>
            <div className='loginItem'>
                <div className='loginFormLabel'>
                账号
                </div>
                <div className='loginFormInput'>
                <Input value={code} onChange={e=>setcode(e)} placeholder='请输入账号'/>
                </div>
            </div>
            <div className='loginItem'>
                <div className='loginFormLabel'>
                密码
                </div>
                <div className='loginFormInput'>
                <Input value={pwd} onChange={e=>setpwd(e)} placeholder='请输入密码'/>
                </div>
            </div>
        </div>
        <div className='loginAction'>
        <div className='successButton' onClick={login}>登录</div>
        </div>
        
    </div>
}